package com.baizhi.controller;

import com.baizhi.News;
import com.baizhi.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class NewsController {
    @Autowired
    private NewsService ns;
    @GetMapping("Newes")
    public List<News> show(){
        return  ns.selectAll();
    }
    @DeleteMapping("Newes/{id}")
    public Map<String,String> delete(@PathVariable("id")int id){
        System.out.println(id);
        boolean delete = ns.delete(id);
        if (delete){
            return new HashMap<String, String>(){{put("code","success");}};
        }
        return new HashMap<String, String>(){{put("code","error");}};
    }
}
